<template>
  <div class="groupList" v-loading="loading">
    <div class="peer-list">
      <list-item v-for="item in peerGroupList" :key="item.id" :item="item" :quickFilter="quickFilter" @getData="getData" v-on="$listeners"></list-item>
      <group-empty v-if="peerGroupList.length === 0" v-on="$listeners"></group-empty>
    </div>
    <el-pagination class="page"
                   v-if="peerGroupList.length > 0"
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   :current-page="current"
                   :page-sizes="[10, 20, 50, 100]"
                   :page-size="size"
                   layout="total, sizes, prev, pager, next, jumper"
                   :total="pageTotal">
    </el-pagination>
  </div>
</template>

<script>
import groupEmpty from '@/views/modules/mspbots/peerGroup/groupList/groupEmpty'
import listItem from '@/views/modules/mspbots/peerGroup/groupList/listItem'
export default {
  name: 'peerList',
  props: ['timeStamp', 'quickFilter', 'filter'],
  components: {
    listItem,
    groupEmpty
  },
  data () {
    return {
      loading: false,
      peerGroupList: [],
      current: 1,
      size: 10,
      pageTotal: 1
    }
  },
  watch: {
    timeStamp (val) {
      this.getData(1)
    }
  },
  methods: {
    async getData (current) {
      this.loading = true
      let params = this.filter
      params.page = {
        current: current || this.current,
        size: this.size
      }
      const { getPeerGroupList } = this.$interface.system
      const { data } = await getPeerGroupList(params)
      if (data.code === 0) {
        this.peerGroupList = data.data.records
        this.pageTotal = Number(data.data.total) || 1
        this.current = Number(data.data.current)
      } else {
        this.$message.error(data.msg)
      }
      this.scrollTop()
      this.loading = false
    },
    handleCurrentChange (val) {
      this.current = val
      this.getData(val)
    },
    handleSizeChange (val) {
      this.size = val
      this.getData(1)
    },
    scrollTop () {
      document.querySelector('.peer-list').scrollTop = 0
    }
  },
  created () {
    // this.getData()
  }
}
</script>

<style scoped lang="scss">
.el-avatar {
  border: 1px solid #0000000F;
}
.groupList {
  height: calc(100% - 56px);
  position: relative;
  padding: 16px 16px 60px 16px;
}
.page {
  position: absolute;
  right: 15px;
  bottom: 15px;
}
.peer-list{
  height: 100%;
  overflow: auto;
}
</style>
